package com.xxxx.server.controller;


import com.xxxx.server.enums.EnabledChangeEnum;
import com.xxxx.server.pojo.Admin;
import com.xxxx.server.pojo.RespBean;
import com.xxxx.server.pojo.Role;
import com.xxxx.server.service.IAdminService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhoubin
 * @since 2020-09-07
 */
@RestController
@RequestMapping("/system")
public class AdminController {

    @Resource
    private IAdminService adminService;

    @GetMapping("/admin")
    @ApiOperation(value = "查询操作员列表")
    public List<Admin> selectAdminList(String keywords){

        //条件查询操作员管理
        List<Admin> adminList = adminService.selectAdminList(keywords);

        return adminList;
    }

    @PutMapping("/admin/")
    @ApiOperation(value = "禁用或启用用户")
    public RespBean enabledChange(@RequestBody Map<String, Object> admin) {

        EnabledChangeEnum enabledChange = adminService.enabledChange(admin);
        switch (enabledChange) {
            case DISABLE:
                return RespBean.success("用户禁用成功");
            case ENABLE:
                return RespBean.success("用户启用成功！");
            default:
                return RespBean.error("无效操作！");
        }
    }

    @DeleteMapping("/admin/{id}")
    @ApiOperation(value = "删除用户")
    public RespBean deleteAdmin(@PathVariable Integer id) {
        adminService.deleteAdminById(id);
        return RespBean.success("用户删除成功！");
    }

    @GetMapping("/admin/roles")
    @ApiOperation(value = "查询所有角色列表")
    public List<Role> selectAllRoleList() {

        return adminService.selectAllRoleList();
    }

    @PutMapping("/admin/role")
    @ApiOperation(value = "修改用户角色")
    public RespBean updateAdminRole(Integer adminId, String rids) {
        adminService.updateAdminRole(adminId, rids);
        return RespBean.success("用户角色信息修改成功！");
    }
}
